using System.Collections;
using System.Collections.Generic;
using System.Linq;
using CurrencyConv.Core;
using NUnit.Framework;
using NUnit.Framework.SyntaxHelpers;

namespace CurrencyConv.Test
{
	[TestFixture]
	public class CurrencyCalculatorFixture
	{
		[Test]
		public void Can_Convert_Currencies_when_given_specific_rate()
		{
			CurrencyCalculator currencyCalculator = new CurrencyCalculator(null);

			Money euro = new Money("EUR", "", 1);

			Money ron = new Money("RON", "", 1);

			Money result = currencyCalculator.ConvertWithRate(ron, euro, 4.3m);

			Assert.That(new Money("EUR", "", 1 / 4.3m), Is.EqualTo(result));
		}

		[Test]
		public void Can_convertCurrencies_when_direct_exchangeRate_found()
		{
			Money euro = new Money("EUR", "", 1);

			Money ron = new Money("RON", "", 1);

			IList<ExchangeRate> exchangeRates = new List<ExchangeRate>
			                                    	{
																							new ExchangeRate(euro,ron,4.3m)
																						};

			CurrencyCalculator currencyCalculator = new CurrencyCalculator(exchangeRates);

			Money converted = currencyCalculator.Convert(euro, ron);

			Assert.That(new Money(ron, 4.3m), Is.EqualTo(converted));
		}

		[Test]
		public void When_converting_to_same_currency_same_value_is_returned()
		{
			Money euro = new Money("EUR", "", 1);

			Money ron = new Money("RON", "", 1);
			Money ron1 = new Money("RON", "", 1);


			IList<ExchangeRate> exchangeRates = new List<ExchangeRate>
			                                    	{
																							new ExchangeRate(euro,ron,4.3m)
																						};

			CurrencyCalculator currencyCalculator = new CurrencyCalculator(exchangeRates);

			Money converted = currencyCalculator.Convert(ron, ron1);

			Assert.That(ron, Is.EqualTo(converted));
		}


		[Test]
		public void When_exchange_rate_not_found_null_is_returned()
		{
			Money euro = new Money("EUR", "", 1);
			Money ron = new Money("RON", "", 1);


			IList<ExchangeRate> exchangeRates = new List<ExchangeRate>();

			CurrencyCalculator currencyCalculator = new CurrencyCalculator(exchangeRates);
			Money converted = currencyCalculator.Convert(euro, ron);

			Assert.That(null, Is.EqualTo(converted));
		}


		[Test]
		public void When_is_inverse_conversion_the_value_returned_is_correct()
		{
			Money euro = new Money("EUR", "", 1);
			Money ron = new Money("RON", "", 1);

			IList<ExchangeRate> exchangeRates = new List<ExchangeRate>
			                                    	{
																							new ExchangeRate(euro,ron,4.3m)
																						};

			CurrencyCalculator currencyCalculator = new CurrencyCalculator(exchangeRates);

			Money converted = currencyCalculator.Convert(ron, euro);

			Assert.That(converted, Is.EqualTo(new Money(euro, 0.23m)));
		}

		[Test]
		public void When_is_indirect_conversion_the_value_returned_is_correct()
		{
			Money hrk = new Money("HRK", "", 1);
			Money euro = new Money("EUR", "", 1);
			Money ron = new Money("RON", "", 1);

			IList<ExchangeRate> exchangeRates = new List<ExchangeRate>
			                                    	{
			                                    		new ExchangeRate(euro, ron, 4.3m),
																							new ExchangeRate(euro, hrk, 7.4m)
			                                    	};

			CurrencyCalculator currencyCalculator = new CurrencyCalculator(exchangeRates);
			Money converted = currencyCalculator.Convert(hrk, ron);

			Assert.That(converted, Is.EqualTo(new Money(ron, 0.6m)));
		}

		[Test]
		public void When_is_indirect_conversion_but_rates_dont_match_null_is_returned()
		{
			Money hrk = new Money("HRK", "", 1);
			Money euro = new Money("EUR", "", 1);
			Money ron = new Money("RON", "", 1);

			IList<ExchangeRate> exchangeRates = new List<ExchangeRate>
			                                    	{
			                                    		new ExchangeRate(euro, ron, 4.3m),
			                                    	};

			CurrencyCalculator currencyCalculator = new CurrencyCalculator(exchangeRates);
			Money converted = currencyCalculator.Convert(hrk, ron);

			Assert.That(converted, Is.EqualTo(null));
		}

		[Test]
		public void When_is_indirect_conversion_but_rates_dont_match_null_is_returned2()
		{
			Money hrk = new Money("HRK", "", 1);
			Money euro = new Money("EUR", "", 1);
			Money ron = new Money("RON", "", 1);

			IList<ExchangeRate> exchangeRates = new List<ExchangeRate>
			                                    	{
			                                    		//new ExchangeRate(euro, ron, 4.3m),
			                                    	};

			CurrencyCalculator currencyCalculator = new CurrencyCalculator(exchangeRates);
			Money converted = currencyCalculator.Convert(hrk, ron);

			Assert.That(converted, Is.EqualTo(null));
		}


		[Test]
		[Ignore]
		public void Test()
		{
			IList<ExchangeRate> exchangeRates = new List<ExchangeRate>
			                                    	{
			                                    		new ExchangeRate(null, null, 4.3m),
			                                    		new ExchangeRate(null, null, 7.4m)
			                                    	};

			var enumerable = from list in exchangeRates
			                 select new { a = new {List = new List<string> {"adfsaf"}}};

			foreach (var asd in enumerable)
			{
				
			}
		}

	}
}